<?php 
class Country_Installer extends Engine_Package_Installer_Module{
    public function onInstall()
    {
        $this->_addCountryProfilePage();
        
        
        parent::onInstall();
    }
    protected function _addCountryProfilePage()
    {
        $db     = $this->getDb();
        $select = new Zend_Db_Select($db);
    
        //
        // Group main page
        //
        // page
    
    
        // Check if it's already been placed
        $select = new Zend_Db_Select($db);
        $select
          ->from('engine4_core_pages')
          ->where('name = ?', 'country_profile_index')
          ->limit(1);
          ;
        $info = $select->query()->fetch();
    
        if( empty($info) ) {
          $db->insert('engine4_core_pages', array(
            'name' => 'country_profile_index',
            'displayname' => 'Country Profile',
            'title' => '',
            'description' => 'This is the profile for a country.',
            'custom' => 0,
            'provides' => 'subject=country',
          ));
          $page_id = $db->lastInsertId('engine4_core_pages');
    
          // containers
          $db->insert('engine4_core_content', array(
            'page_id' => $page_id,
            'type' => 'container',
            'name' => 'main',
            'parent_content_id' => null,
            'order' => 1,
            'params' => '',
          ));
          $container_id = $db->lastInsertId('engine4_core_content');
    
          $db->insert('engine4_core_content', array(
            'page_id' => $page_id,
            'type' => 'container',
            'name' => 'middle',
            'parent_content_id' => $container_id,
            'order' => 3,
            'params' => '',
          ));
          $middle_id = $db->lastInsertId('engine4_core_content');
    
          $db->insert('engine4_core_content', array(
            'page_id' => $page_id,
            'type' => 'container',
            'name' => 'left',
            'parent_content_id' => $container_id,
            'order' => 1,
            'params' => '',
          ));
          $left_id = $db->lastInsertId('engine4_core_content');
    
          $db->insert('engine4_core_content', array(
            'page_id' => $page_id,
            'type' => 'widget',
            'name' => 'country.country-header',
            'parent_content_id' => $middle_id,
            'order' => 1,
            'params' => '',
          ));
          
        }
    }
}
?>